import os
import time
from datetime import datetime
def run_Task():
    db_backup_name = r"d:\db_backup\crm_%s.sql" % (time.strftime("%Y%m%d%H%M"))
    print(db_backup_name)
    cmd = "mysqldump --defaults-extra-file=D:\db_backup\config.cnf base_db2 --default_character-set=utf8 >{}".format(db_backup_name)
    print("begin to dump mysql database crm...");
    print("begin backup")
    print(cmd)
    os.system(cmd)
    print("done,backups")
def timerFun(sched_Timer):
    while True:
        now = str(time.strftime('%Y-%m-%d&%H:%M:%S', time.localtime())).split("&")[1]
        if now == sched_Timer:
            time.sleep(1)
            run_Task()
if __name__ == "__main__":
    startime = "17:30:00"
    sched_Timer = str(datetime.strptime(startime,'%H:%M:%S')).split(" ")[1]
    print(sched_Timer)
    print("run the timer task at {0}".format(sched_Timer))
    timerFun(sched_Timer)
